package com.atguigu.serviceedu.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.entity.EduCourse;
import com.atguigu.serviceedu.entity.EduTeacher;
import com.atguigu.serviceedu.service.EduCourseService;
import com.atguigu.serviceedu.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
//@CrossOrigin
@RequestMapping("/eduservice/frontTeacher")
public class FrontTeacherController {
    //获取service
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;
    @PostMapping("frontPageTeacher/{page}/{limit}")
    public R getFrontPageTeacher(@PathVariable Long page,@PathVariable Long limit){
        Page<EduTeacher> teacherPage = new Page<>(page,limit);
        //分页查询获取分页中的信息放到map集合中
        Map<String,Object> teacherMap = teacherService.getFrontPageTeacher(teacherPage);
        return R.ok().data(teacherMap);
    }
    //根据教师id获取教师信息，和对应的课程信息
    @GetMapping("getFrontTeacherAndCourse/{teacherId}")
    public R getFrontTeacherAndCourse(@PathVariable String teacherId){
        EduTeacher frontTeacher = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> frontCourseList = courseService.list(wrapper);
        return R.ok().data("frontTeacher",frontTeacher).data("frontCourse",frontCourseList);
    }

}
